package com.users.rn.common.init;

import android.content.Context
import android.content.Intent
import com.users.rn.common.download.RNPluginDownloadManager
import com.liulishuo.filedownloader.FileDownloader
import com.users.rn.rncommon.basic.RNReactModulesPackage
import com.users.rn.rncommon.init.RNInitInterface
import com.users.rn.rncommon.manager.ALHReactEnvManager
import com.users.rn.rncommon.plugin.ReactSourceCode
import com.users.rn.rncommon.util.RNLogger
import java.io.File

/**
 * @Description:
 * @Author: bluce
 * @Date: 2020/12/3 14:04
 */
object ALHReactNativeInit {
    const val TAG = "ALHReactNativeInit"

    private lateinit var initInterface: RNInitInterface

    @JvmStatic
    fun initialize(inter: RNInitInterface) {
        initInterface = inter
        FileDownloader.setup(inter.context)
        updatePlugins(inter.context)
        RNReactModulesPackage.registerNativeModule(ReactSourceCode::class.java)
        ALHReactEnvManager.getInstance().init(initInterface.context)
    }

    fun getInitInterface(): RNInitInterface? {
        if (initInterface == null) {
            RNLogger.e(TAG, "为初始化init");
            return null;
        }
        return initInterface;
    }

    private fun updatePlugins(context: Context) {
        RNPluginDownloadManager.connect(context,"",null)
//        context.startService(Intent(context.applicationContext, ALHPluginDownloadService::class.java))
    }
}
